package com.lx.spring.context.demo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StringValueResolver;

/**
 * 接口 Aware 在spring中通过回调方法的模式实现各种信息获取与自定义
 * ApplicationContextAware 获取 ApplicationContext
 * BeanNameAware 获取beanName
 * EmbeddedValueResolverAware 使用spring容器组件解析字符串 根据spel expression 规则
 */

@Component
public class Red implements ApplicationContextAware, BeanNameAware, EmbeddedValueResolverAware {

   private ApplicationContext applicationContext;



    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("ioc: "+ applicationContext);
        this.applicationContext = applicationContext;
    }

    public void setBeanName(String s) {
        System.out.println("this bean name : " + s);
    }

    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        String rs = resolver.resolveStringValue("你好 ${os.name} 我是 #{20*18}");
        System.out.println("解析的字符串："+ rs);
    }
}
